package com.xhh.microfin.dispatch.service.process.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 003035
 * @Date: 2019/1/21
 */
public class ProcessContext {

    private Integer processInstanceId;

    private String businessId;

    public Integer getCurrentTaskId() {
        return currentTaskId;
    }

    public void setCurrentTaskId(Integer currentTaskId) {
        this.currentTaskId = currentTaskId;
    }

    private Integer currentTaskId;

    public Map<String, Var> getVars() {
        return vars;
    }

    private Map<String,Var> vars = new HashMap<>();

    public Integer getProcessInstanceId() {
        return processInstanceId;
    }

    public String getBusinessId() {
        return businessId;
    }

    public void setBusinessId(String businessId) {
        this.businessId = businessId;
    }

    public void setProcessInstanceId(Integer processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    public String getVar(String key) {

        if (!vars.containsKey(key)) {
            return "";
        }
        return vars.get(key).getValue();
    }

    public void add(Var var) {
        if (!vars.containsKey(var.getVarCode())) {
            vars.put(var.getVarCode(), var);
        } else {
            Var var1 = vars.get(var.getVarCode());
            if (var.getCtime().compareTo(var1.getCtime()) == 1) {
                vars.put(var.getVarCode(), var);
            }
        }
    }

    public void addAll(List<Var> list) {
        for (Var var : list) {
            add(var);
        }
    }
}
